package com.newsproject.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.newsproject.service.SearchInUserPageService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

@Api(tags="搜索个人新闻")
@RestController
@ApiResponses(value = {
            @ApiResponse(code = 200, message = "成功"),
            @ApiResponse(code = 400, message = "请求参数错误"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
@RequestMapping("/searchInUserPageController")
public class SearchInUserPageController {
    @Autowired 
    private SearchInUserPageService searchInUserPageService;

    // 获取搜索结果
    /*@ApiOperation(value="获取搜索结果",notes="根据用户ID、搜索字符串（可选）、时间范围（可选）、分类ID（可选）、审核状态（可选）获取搜索结果")
    @GetMapping("search/{user_id}")
    public ModelAndView search(@ApiParam(value="用户ID",required=true) @PathVariable("user_id") int user_id,
                               @ApiParam("搜索字符串") @RequestParam(value = "title", required = false) String title,
                               @ApiParam("起始时间") @RequestParam(value = "start_time", required = false) String start_time,
                               @ApiParam("结束时间") @RequestParam(value = "end_time", required = false) String end_time,
                               @ApiParam("分类ID") @RequestParam(value = "category_id", required = false) Integer category_id,
                               @ApiParam("审核状态0-未审核，1-审核通过，2-审核未通过") @RequestParam(value = "audit_status", required = false) Integer audit_status) {
        
        return searchInUserPageService.search(user_id, title, start_time, end_time, category_id, audit_status);
    }*/

    // 获取文章结果
    @ApiOperation(value="获取文章搜索结果",notes="（json）根据用户ID、搜索字符串（可选）、时间范围（可选）、分类ID（可选）、审核状态（可选）获取搜索结果")
    @GetMapping("category_1/{user_id}")
    public Map<String, Object> category_1(@ApiParam(value="用户ID",required=true) @PathVariable("user_id") int user_id,
                               @ApiParam("搜索字符串") @RequestParam(value = "title", required = false) String title,
                               @ApiParam("起始时间") @RequestParam(value = "start_time", required = false) String start_time,
                               @ApiParam("结束时间") @RequestParam(value = "end_time", required = false) String end_time,
                               @ApiParam("搜索页数") @RequestParam(value = "page", defaultValue = "1",required = true) int page,
                               @ApiParam("审核状态0-未审核，1-审核通过，2-审核未通过") @RequestParam(value = "audit_status", required = false) Integer audit_status) {
        
        return searchInUserPageService.Search(user_id, title, start_time, end_time, 1, audit_status,page);
    }

    // 获取微头条结果
    @ApiOperation(value="获取微头条搜索结果",notes="（json）根据用户ID、搜索字符串（可选）、时间范围（可选）、分类ID（可选）、审核状态（可选）获取搜索结果")
    @GetMapping("category_2/{user_id}")
    public Map<String, Object> category_2(@ApiParam(value="用户ID",required=true) @PathVariable("user_id") int user_id,
                               @ApiParam("搜索字符串") @RequestParam(value = "title", required = false) String title,
                               @ApiParam("起始时间") @RequestParam(value = "start_time", required = false) String start_time,
                               @ApiParam("结束时间") @RequestParam(value = "end_time", required = false) String end_time,
                               @ApiParam("搜索页数") @RequestParam(value = "page", defaultValue = "1",required = true) int page,
                               @ApiParam("审核状态0-未审核，1-审核通过，2-审核未通过") @RequestParam(value = "audit_status", required = false) Integer audit_status) {
        
        return searchInUserPageService.Search(user_id, title, start_time, end_time, 2, audit_status,page);
    }

    // 获取收藏结果
    @ApiOperation(value="获取收藏搜索结果",notes="（json）根据用户ID、搜索字符串（可选）、时间范围（可选）、分类ID（可选）、审核状态（可选）获取搜索结果")
    @GetMapping("category_3/{user_id}")
    public Map<String, Object> category_3(@ApiParam(value="用户ID",required=true) @PathVariable("user_id") int user_id,
                               @ApiParam("搜索字符串") @RequestParam(value = "title", required = false) String title,
                               @ApiParam("起始时间") @RequestParam(value = "start_time", required = false) String start_time,
                               @ApiParam("结束时间") @RequestParam(value = "end_time", required = false) String end_time,
                               @ApiParam("搜索页数") @RequestParam(value = "page", defaultValue = "1",required = true) int page,
                               @ApiParam("审核状态0-未审核，1-审核通过，2-审核未通过") @RequestParam(value = "audit_status", required = false) Integer audit_status) {
        
        return searchInUserPageService.Search_bookmark(user_id, title, start_time, end_time, audit_status,page);
    }
}